#ifndef _WEBAPPLIB_SOCKETREADER_H_
#define _WEBAPPLIB_SOCKETREADER_H_ 

#include <string>
#include <vector>
#include <map>
#include "waString.h"

using namespace std;

#define READBUFLEN 2048

/// Web Application Library namaspace
namespace webapp {
	
	class waSocket
	{
	public:
		waSocket( const string & ip, int port );
		
		~waSocket();
			
		int Connect();
		
		int FD(){ return m_iFD; }
	private:
		string m_sIP;
		int m_iPort;
		int m_iFD;
	};

	class waSocketWriter
	{
	public:
		waSocketWriter( waSocket & socket );
	
		int Write( const char * pcBuf, unsigned int iBufLen );
	private:
		int m_iFD;
	};

	class waSocketReader
	{
	public:
		waSocketReader( waSocket & sock );
		waSocketReader( int iFd );

		~waSocketReader(){};

		int ReadLine( string &sLine );

		int ReadN( const int iWanted, string & sBuf );

		int ReadnWait( char *pBuf, int iLen);
	private:	
		int ReadChar( char *ptr );
		int ReadSocket();
		int Readn( char *pBuf, int iMaxLen);

	private:
		int m_iFD;
		char * m_pReadPtr;
		int m_iReadCount;
		char m_sReadBuf[ READBUFLEN ];
	};
}

#endif
